<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>017非父子组件之间的传值-自复习</title>
  <script src="./vue.js"></script>
</head>
<body>
  <div id="root">
    <child :content="one"></child>
    <child :content="two"></child>
  </div>
  <script>
    Vue.prototype.bus = new Vue();
    var vm = new Vue({
      el: "#root",
      data: {
        one: "up",
        two: "down"
      },
      components: {
        "child": {
          props:{
            content: {
              type: String
            }
          },
          data: function() {
            return {
              selfContent: this.content
            }
          },
          template: "<div @click='handleClick'>{{selfContent}}</div>",
          methods: {
            handleClick: function() {
              console.log(this.selfContent);
              this.bus.$emit("change", this.selfContent);
            }
          },
          mounted: function() {
            var this_ = this;
            this.bus.$on("change", function(msg) {
              alert(msg);
              this_.selfContent = msg;
            })
          }
        }
      }
    })
  </script>
</body>
</html>